import 'package:flutter/material.dart';

import '../my_image.dart';

class MyIconButton extends StatelessWidget {
  final VoidCallback? onPressed;
  final Widget icon;
  final Color? color;
  final Color? backgroundColor;
  final bool isEnable;
  final double size;
  final double? radius;
  final double elevation;
  final EdgeInsetsGeometry? padding;

  const MyIconButton({
    Key? key,
    required this.icon,
    required this.onPressed,
    this.color,
    this.backgroundColor,
    this.isEnable = true,
    this.size = 48,
    this.radius,
    this.elevation = 0,
    this.padding,
  }) : super(key: key);

  factory MyIconButton.img(
    String path, {
    double? size,
    double? iconSize,
    double? radius,
    double elevation = 0,
    Color? color,
    Color? backgroundColor,
    bool isEnable = true,
    required VoidCallback onPressed,
  }) {
    return MyIconButton(
      icon: MyImage(
        path,
        width: iconSize ?? 20,
        height: iconSize ?? 20,
        color: color,
      ),
      onPressed: onPressed,
      color: color,
      backgroundColor: backgroundColor,
      isEnable: isEnable,
      size: size ?? 48,
      radius: radius,
      elevation: elevation,
    );
  }

  Widget _widget() {
    return Container(
      width: size,
      height: size,
      alignment: Alignment.center,
      child: IconButton(
        padding: padding,
        splashRadius: radius ?? size / 2,
        icon: icon,
        onPressed: isEnable ? onPressed : null,
        color: color,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      color: backgroundColor ?? Colors.transparent,
      elevation: elevation,
      borderRadius: BorderRadius.circular(radius ?? size / 2),
      child: _widget(),
    );
  }
}
